package com.faithnmn.learnenglish.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Timestamp;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.TimeUnit;
import org.ocpsoft.prettytime.impl.DurationImpl;

import android.os.Environment;

public class CommonUtil {
	public static void writeToFile(String content, String filename,boolean isAppend) {
		String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Logs/HocTiengAnh30Phut" ;
		File file = new File(path);
		try {
			if(file.mkdirs()||file.exists()){
				path+="/"+filename;
				BufferedWriter out = new BufferedWriter(new FileWriter(path,isAppend));
				out.write(content);
				out.close();
			}
			
		} catch (Exception e) {
			System.out.println("Exception " + e.toString());
		}

	}
	
	public static String convertFBUnixtime(String fbUnixtime){
		Date date = new Date(Long.parseLong(fbUnixtime)*1000L); // *1000 is to convert seconds to milliseconds
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd-MM-yyyy"); // the format of your date
		sdf.setTimeZone(TimeZone.getTimeZone("GMT+7"));
		return sdf.format(date);
	}
	
	public static String getPrettyTime(long unixTime){
		PrettyTime pt= new PrettyTime();
		return pt.format(new Date(unixTime));
	}
	
}
